package cn.life.business.apply.controller;

import cn.life.business.apply.entity.po.ApplyPo;
import cn.life.business.apply.entity.vo.ApplyVo;
import cn.life.business.apply.service.ApplyService;
import cn.life.business.audit.entity.po.AuditPo;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import cn.life.common.entity.po.MessagePo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 王振宇
 * @Description: 街道提交申请控制层
 * @Date 2018-09-18 10:57:16
 */
@RestController
@RequestMapping("apply")
public class ApplyController {

    @Autowired
    private ApplyService applyService;

    /**
     * @param applyPo,myUserInfo
     * @return
     * @Description: 自动添加项
     */
    public ApplyPo getOpr(ApplyPo applyPo, @MyUser MyUserInfo myUserInfo) {
        applyPo.setOprUserId(myUserInfo.getUserId());
        applyPo.setOprUserName(myUserInfo.getUserName());
        applyPo.setOprDate(new Date());
        return applyPo;
    }

    /**
     * @param
     * @Description: 新增申请记录
     * @return:
     * @Author 王振宇
     * @Date 2018/09/18
     */
    @PostMapping(value = "/addapply")
    public CMessage AddApply(HttpServletRequest request, @RequestBody ApplyPo applyPo, @MyUser MyUserInfo myUserInfo) {
        getOpr(applyPo, myUserInfo);
        return applyService.AddApply(request,applyPo);
    }

    /**
     * @param
     * @Description: 新增申请待审记录
     * @return:
     * @Author 王振宇
     * @Date 2018/09/18
     */
    @PostMapping(value = "/addApplyAudit")
    public CMessage addApplyAudit(@RequestBody ApplyPo applyPo, @MyUser MyUserInfo myUserInfo) {
        getOpr(applyPo, myUserInfo);
        return applyService.addApplyAudit(applyPo);
    }


    /**
     * @param
     * @Description: 查询申请记录
     * @return:
     * @Author 王振宇
     * @Date 2018/09/19
     */
    @PostMapping(value = "/queryapply")
    public CMessage queryList(@RequestBody ApplyVo applyVo, @MyUser MyUserInfo myUserInfo) {
        applyVo.setQueryUserName(myUserInfo.getUserName());
        applyVo.setUserState(myUserInfo.getState());
        return applyService.queryList(applyVo);
    }


    /**
     * @param
     * @Description: 单条查询申请列表和图片明细表
     * @return:
     * @Author 王振宇
     * @Date 2018/09/19
     */
    @PostMapping(value = "/qureysinple")
    public CMessage querySinple(@RequestBody ApplyVo applyVo) {
        return applyService.querySingle(applyVo);
    }

    /**
     * @param
     * @Description: 修改申请
     * @return:
     * @Author 王振宇
     * @Date 2018/09/20
     */
    @PostMapping(value = "/update")
    public CMessage update(@RequestBody ApplyPo applyPo){
        return applyService.update(applyPo);
    }

    /**
     * @param
     * @Description: 删除申请
     * @return:
     * @Author 王振宇
     * @Date 2018/09/20
     */
    @PostMapping(value = "/delete")
    public CMessage delete(@RequestBody ApplyPo applyPo){
        return applyService.delete(applyPo);
    }

    /**
     * @Description: 导出申请单
     * @param applyVo
     * @return
     */
    @PostMapping(value = "/exportPdf")
    public CMessage exportPdf(HttpServletRequest request,@RequestBody ApplyVo applyVo){
        return applyService.exportPdf(request,applyVo);
    }

    /**
     * @Description: 发送短信验证码
     * @param messagePo
     * @return
     */
    @PostMapping(value = "/sendMessage")
    public CMessage sendMessage(@RequestBody MessagePo messagePo){
        return applyService.sendMessage(messagePo);
    }

    /**
     * @Description: 校验短信验证码
     * @param messagePo
     * @return
     */
    @PostMapping(value = "/checkMessage")
    public CMessage checkMessage(@RequestBody MessagePo messagePo){
        return applyService.checkMessage(messagePo);
    }
}
